<?php
$id=$_GET['id'];
$row=Page::fetch_by_id($id);
eval(Common::define_var_from_array($row));
if(isset($_POST['submit_value']))
{
	$array=$_POST;
	$array['page_status']=1;
	if(!isset($array['page_focus']))
		$array['page_focus']=0;
	else
	{
		$query="UPDATE tbl_page SET page_focus=0 WHERE page_status=1 AND page_group_id='$page_group_id' ";
		Db::mysql_query($query,FETCH_MODE_NONE);
	}
	unset($array['submit_value']);
	Page::save_by_id($id,$page_group_id,$array);
	if($_POST['submit_value']=='Lưu & Đóng')
		Common::header_location(null,null,"$('#btn_close').trigger('click')");
	else if($_POST['submit_value']=='Lưu & Thêm mới')
		Common::header_location(null,"popup.php?page=_page-insert&group_id=$page_group_id");
	else if($_POST['submit_value']=='Xóa')
	{
		$query="DELETE FROM tbl_page WHERE page_id='$id' ";
		Db::mysql_query($query,FETCH_MODE_NONE);
		Common::header_location('Xóa thành công!',null,"$('#btn_close').trigger('click')");
	}
	else
		Common::header_location(null,"popup.php?page=_page-update-$page_group_id&id=$id");
}
$back_link='index.php?page='.Page::fetch_group_alias_from_group_id($page_group_id);
?>

<form method='post' class='form'>
	<label>
		<strong>Tiêu đề</strong>
		<input type='text' name='page_title' class='required' value='<?php echo $page_title;?>'/>
	</label>
	<label>
		<strong>Hình ảnh</strong>
		<input type="text" class='finder' name='page_image'  value='<?php echo $page_image;?>'/>
	</label>
	<label>
		<strong>Trích dẫn</strong>
		<input type='text' name='page_quote' class='required' value='<?php echo $page_quote;?>'/>
	</label>
	<label>
		<strong>Nội dung</strong>
		<textarea name='page_content' toolbar='Full' class='editor'><?php echo $page_content;?></textarea>
	</label>
	<label>
		<strong>Tin nổi bật</strong>
		<input <?php echo $page_focus==1?" checked='checked' ":"";?> type='checkbox' value='1' name='page_focus'/> Check vào nếu là tin nổi bật
	</label>
	<div style='text-align:right;padding:4px'>
		<input type='submit' value='Lưu' name='submit_value'/>
		<input type='submit' value='Lưu & Thêm mới' name='submit_value'/>
		<input type='submit' value='Lưu & Đóng' name='submit_value'/>
		<input type='submit' value='Xóa' name='submit_value' onclick="
			if(!confirm('Bạn có đồng ý xóa không?'))
				return false;
		"/>		
		<input type='button' value='Đóng' id='btn_close' onclick="
			if(window.opener)
			{
				window.opener.location.reload();
				window.close();
			}
			else 
			{
				window.location='<?php echo $back_link?>';
			}
		"/>
	</div>
</form>